package guoanmaker.provider.business.repository;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import guoanmaker.provider.business.model.PersonalFinanceProject;

/**
 * 
 * @author ws
 * 2017-12-19
 */
public interface PersonalFinanceProjectRepository  extends JpaRepository<PersonalFinanceProject, String>, JpaSpecificationExecutor<PersonalFinanceProject>{

	@Query("select count(id) from PersonalFinanceProject where personalUserId = :userId")
	long findTotalByUserId(@Param("userId") String userId);
	
	@Query("select count(id) from PersonalFinanceProject where id = :projectId")
	long findCountByProjectId(@Param("projectId") String projectId);
	
	@Modifying
	@Query("update PersonalFinanceProject set status = :status, updateTime = :updateTime where id = :projectId")
	void updateStatus(@Param("projectId") String projectId, @Param("status") Integer status, @Param("updateTime") Date updateTime);

	@Query("select count(id) from PersonalFinanceProject where personalUserId = :userId and status = :status")
	long findTotalByUserIdAndStatus(@Param("userId") String userId, @Param("status") Integer status);
	
	@Query("select count(id) from PersonalFinanceProject where status = :status")
	long findTotalByStatus(@Param("status") Integer status);
	
}
